package com.wbk.lotterysystemuserservice.controller.auth.biz;

import com.wbk.lotterysystemuserservice.commons.bo.UserExtBO;
import com.wbk.lotterysystemuserservice.entity.UserExt;
import com.wbk.lotterysystemuserservice.service.UserExtInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import result.Result;


@Component
public class UserExtBiz {

    @Autowired
    UserExtInfoService userExtInfoService;

    @Transactional(propagation = Propagation.REQUIRED)
    public Result save(UserExtBO userExtBO) {
        UserExt userExt = userExtInfoService.getUserExt(userExtBO.getUserNo());
        if (userExt == null) {
            return new Result(100, "找不到用户信息", null);
        }
        if (userExtBO.getHeadImagUrl() != null) {
            if (!userExtBO.getHeadImagUrl().equals(userExt.getHeadImgUrl()) && userExtBO.getHeadImagUrl().trim().length() != 0) {
                userExt.setHeadImgUrl(userExtBO.getHeadImagUrl());
            }
        }
        if (userExtBO.getInfo() != null) {
            if (!userExtBO.getInfo().equals(userExt.getInfo())) {
                userExt.setInfo(userExtBO.getInfo());
            }
        }
        userExtInfoService.update(userExt);
        return new Result(200, "修改成功", null);
    }
}
